home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / getting there / Apps / MOO-1.7.6.src / inc / ast.h next >
Text File  |  1994-11-02  |  5KB  |  217 lines

  1. /******************************************************************************
  2.   Copyright (c) 1992 Xerox Corporation.  All rights reserved.
  3.   Portions of this code were written by Stephen White, aka ghond.
  4.   Use and copying of this software and preparation of derivative works based
  5.   upon this software are permitted.  Any distribution of this software or
  6.   derivative works must comply with all applicable United States export
  7.   control laws.  This software is made available AS IS, and Xerox Corporation
  8.   makes no warranty about the software, its performance or its conformity to
  9.   any specification.  Any person obtaining a copy of this software is requested
  10.   to send their name and post office or electronic mail address to:
  11.     Pavel Curtis
  12.     Xerox PARC
  13.     3333 Coyote Hill Rd.
  14.     Palo Alto, CA 94304
  15.     Pavel@Xerox.Com
  16.  *****************************************************************************/
  17.  
  18. #ifndef AST_h
  19. #define AST_h 1
  20.  
  21. #include "config.h"
  22. #include "parser.h"
  23. #include "structures.h"
  24. #include "sym_table.h"
  25.  
  26. typedef unsigned Label;
  27.  
  28. struct Expr_Ident {
  29.     const char           *name;
  30.     unsigned        slot;
  31. };
  32.  
  33. struct Expr_Binary {
  34.     Expr                  *lhs, *rhs;
  35. };
  36.  
  37. enum Arg_Kind {
  38.     ARG_NORMAL, ARG_SPLICE
  39. };
  40.  
  41. struct Arg_List {
  42.     Arg_List           *next;
  43.     enum Arg_Kind    kind;
  44.     Expr           *expr;
  45. };
  46.  
  47. struct Expr_Call {
  48. /*    enum Function    func;*/
  49.     unsigned           func;
  50.     Arg_List           *args;
  51. };
  52.  
  53. struct Expr_Verb {
  54.     Expr           *obj, *verb;
  55.     Arg_List           *args;
  56. };
  57.  
  58. struct Expr_Range {
  59.     Expr           *base, *from, *to;
  60. };
  61.  
  62. enum Asgn_Kind {
  63.     ASGN_VAR, ASGN_PROP, ASGN_REF, ASGN_RANGE
  64. };
  65.  
  66. union Asgn_Data {
  67.     struct Expr_Ident    id;
  68.     struct Expr_Binary  bin;
  69.     struct Expr_Range    range;
  70. };
  71.  
  72. struct Expr_Asgn {
  73.     enum Asgn_Kind    kind;
  74.     union Asgn_Data    a;
  75.     Expr           *value;
  76. };
  77.  
  78. struct Expr_Cond {
  79.     Expr           *condition, *consequent, *alternate;
  80. };
  81.  
  82. enum Expr_Kind {
  83.     EXPR_VAR, EXPR_ID,
  84.     EXPR_PROP, EXPR_VERB,
  85.     EXPR_INDEX, EXPR_RANGE,
  86.     EXPR_ASGN, EXPR_CALL,
  87.     EXPR_PLUS, EXPR_MINUS, EXPR_TIMES, EXPR_DIVIDE, EXPR_MOD, EXPR_NEGATE,
  88.     EXPR_AND, EXPR_OR, EXPR_NOT,
  89.     EXPR_EQ, EXPR_NE, EXPR_LT, EXPR_LE, EXPR_GT, EXPR_GE,
  90.     EXPR_IN, EXPR_LIST, EXPR_COND,
  91.     SizeOf_Expr_Kind /* The last element is also the number of elements... */
  92. };
  93.  
  94. union Expr_Data {
  95.     Var            var;
  96.     struct Expr_Ident    id;
  97.     struct Expr_Binary    bin;
  98.     struct Expr_Call    call;
  99.     struct Expr_Verb    verb;
  100.     struct Expr_Range    range;
  101.     struct Expr_Asgn    asgn;
  102.     struct Expr_Cond    cond;
  103.     Expr           *expr;
  104.     Arg_List           *list;
  105. };
  106.  
  107. struct Expr {
  108.     enum Expr_Kind    kind;
  109.     union Expr_Data    e;
  110. };
  111.  
  112. struct Stmt_Cond {
  113.     struct Cond_Arm    *arms;
  114.     Stmt           *otherwise;
  115. };
  116.  
  117. struct Cond_Arm {
  118.     struct Cond_Arm    *next;
  119.     Expr           *condition;
  120.     Stmt           *stmt;
  121. };
  122.  
  123. struct Stmt_List {
  124.     struct Expr_Ident    id;
  125.     Expr           *expr;
  126.     Stmt           *body;
  127. };
  128.  
  129. struct Stmt_Range {
  130.     struct Expr_Ident    id;
  131.     Expr           *from, *to;
  132.     Stmt           *body;
  133. };
  134.  
  135. struct Stmt_Loop {
  136.     Expr           *condition;
  137.     Stmt           *body;
  138. };
  139.  
  140. struct Stmt_Fork {
  141.     struct Expr_Ident    id;
  142.     Expr           *time;
  143.     Stmt           *body;
  144. };
  145.  
  146. enum Stmt_Kind {
  147.     STMT_COND, STMT_LIST, STMT_RANGE, STMT_WHILE, STMT_FORK, STMT_EXPR,
  148.     STMT_RETURN
  149. };
  150.  
  151. union Stmt_Data {
  152.     struct Stmt_Cond    cond;
  153.     struct Stmt_List    list;
  154.     struct Stmt_Range    range;
  155.     struct Stmt_Loop    loop;
  156.     struct Stmt_Fork    fork;
  157.     Expr           *expr;
  158. };
  159.  
  160. struct Stmt {
  161.     Stmt           *next;
  162.     enum Stmt_Kind    kind;
  163.     union Stmt_Data    s;
  164. };
  165.     
  166.  
  167. extern void    begin_code_allocation(void);
  168. extern void    end_code_allocation(int);
  169.  
  170. extern Stmt    *alloc_stmt(enum Stmt_Kind);
  171. extern Cond_Arm    *alloc_cond_arm(Expr *, Stmt *);
  172. extern Expr    *alloc_expr(enum Expr_Kind);
  173. extern Expr    *alloc_var(var_type);
  174. extern Expr    *alloc_binary(enum Expr_Kind, Expr *, Expr *);
  175. extern Expr    *alloc_verb(Expr *, Expr *, Arg_List *);
  176. extern Arg_List    *alloc_arg_list(enum Arg_Kind, Expr *);
  177. extern Expr    *alloc_asgn(enum Asgn_Kind, Expr *);
  178. extern const char *ak_alloc_string(const char *);
  179. extern void    ak_dealloc_string(const char *);
  180.  
  181. extern void    deallocate(void *);
  182.  
  183. extern Program *new_program_copying_stmt(Stmt *, unsigned, Names **);
  184.  
  185. /*extern void    add_ref_to_program(Program *); */
  186. extern void    free_program(Program *);
  187. extern void     free_stmt(Stmt *);
  188.  
  189. #endif /* !AST_h */
  190.  
  191. /* $Log: ast.h,v $
  192.  * Revision 1.8  1992/10/23  23:03:47  pavel
  193.  * Added copyright notice.
  194.  *
  195.  * Revision 1.7  1992/10/21  03:02:35  pavel
  196.  * Converted to use new automatic configuration system.
  197.  *
  198.  * Revision 1.6  1992/08/31  22:21:43  pjames
  199.  * Changed some `char *'s to `const char *'
  200.  *
  201.  * Revision 1.5  1992/08/28  23:13:36  pjames
  202.  * Added ASGN_RANGE to assignment type enumeration.
  203.  * Added range arm to assigment union.
  204.  *
  205.  * Revision 1.4  1992/08/14  00:15:28  pavel
  206.  * Removed trailing comma in an enumeration.
  207.  *
  208.  * Revision 1.3  1992/08/14  00:01:11  pavel
  209.  * Converted to a typedef of `var_type' = `enum var_type'.
  210.  *
  211.  * Revision 1.2  1992/07/30  21:21:21  pjames
  212.  * Removed max_stack from AST structures.
  213.  *
  214.  * Revision 1.1  1992/07/20  23:23:12  pavel
  215.  * Initial RCS-controlled version.
  216.  * */
  217.